package com.salelogistics.basic.utils;

import cn.hutool.core.date.DateTime;
import com.salelogistics.basic.domain.*;
import com.salelogistics.common.core.utils.StringUtils;
import com.salelogistics.common.security.utils.SecurityUtils;
import org.apache.poi.hpsf.Decimal;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class CheckParameterUtil {
    public boolean checkParameter(Object object, String tableName) {
        boolean flag = false;
        switch (tableName) {
            case "basBuildUnit":
                BasBuildUnit basBuildUnit = (BasBuildUnit) object;
                if (basBuildUnit != null
                        && StringUtils.isNotEmpty(basBuildUnit.getBuildName())
                        && StringUtils.isNotEmpty(basBuildUnit.getMailingAddress())
                        && StringUtils.isNotEmpty(basBuildUnit.getContactPerson())) {
                    flag = true;
                }
                break;
            case "basCarrier":
                BasCarrier basCarrier = (BasCarrier) object;
                if (basCarrier != null
                        && StringUtils.isNotEmpty(basCarrier.getCarrierName())
                        && (basCarrier.getRegisteredCapital() != null && basCarrier.getRegisteredCapital()
                        .compareTo(new BigDecimal(30)) >= 0)
                        && StringUtils.isNotEmpty(basCarrier.getBusinessContact())
                        && StringUtils.isNotEmpty(basCarrier.getPrincipalPhone())) {
                    flag = true;
                }
                break;
            case "basContract":
                BasContract basContract = (BasContract) object;
                if (basContract != null
                        && StringUtils.isNotEmpty(basContract.getCommunityName())
                        && StringUtils.isNotEmpty(basContract.getContractName())
                        && StringUtils.isNotEmpty(basContract.getEndTime())
                        && StringUtils.isNotEmpty(basContract.getContractType())) {
                    flag = true;
                }
                break;

            case "basLot":
                BasLot basLot = (BasLot) object;
                if (basLot != null
                        && StringUtils.isNotEmpty(basLot.getName())
                        && (basLot.getMiles() != null && basLot.getMiles().compareTo(new BigDecimal(0)) >= 0)) {
                    flag = true;
                }
                break;

            case "basMaterial":
                BasMaterial basMaterial = (BasMaterial) object;
                if (basMaterial != null
                        && StringUtils.isNotEmpty(basMaterial.getMaterialName())
                        && StringUtils.isNotEmpty(basMaterial.getSpecifications())
                        && StringUtils.isNotEmpty(basMaterial.getSteelNumber())
                        && (basMaterial.getLength() != null && basMaterial.getLength().compareTo(new BigDecimal(0)) >= 0)
                        && (basMaterial.getTaxRate() != null && basMaterial.getTaxRate().compareTo(new BigDecimal(0)) >= 0)
                        && (basMaterial.getStatus() != null && basMaterial.getStatus() >= 0)
                ) {
                    flag = true;
                }
                break;

            case "basRoutes":
                BasRoutes basRoutes = (BasRoutes) object;
                if (basRoutes != null
                        && StringUtils.isNotEmpty(basRoutes.getRouteName())
                        && StringUtils.isNotEmpty(basRoutes.getStartLocation())
                        && StringUtils.isNotEmpty(basRoutes.getEndLocation())
                ) {
                    flag = true;
                }
                break;

            case "basStation":
                BasStation basStation = (BasStation) object;
                if (basStation != null
                        && StringUtils.isNotEmpty(basStation.getStationName())
                        && basStation.getRouteId() != null
                        && (basStation.getStationOrder() != null && basStation.getStationOrder() >= 0)

                ) {
                    flag = true;
                }
                break;

            case "basSupplier":
                BasSupplier basSupplier = (BasSupplier) object;
                if (basSupplier != null
                        && StringUtils.isNotEmpty(basSupplier.getSupplierName())) {
                    flag = true;
                }
                break;

            case "basVehicleInfo":
                BasVehicleInfo basVehicleInfo = (BasVehicleInfo) object;
                if (basVehicleInfo != null
                        && StringUtils.isNotEmpty(basVehicleInfo.getNumberPlate())
                        && StringUtils.isNotEmpty(basVehicleInfo.getNumberPlate())
                        && StringUtils.isNotEmpty(basVehicleInfo.getOperatingLicense())
                        && (basVehicleInfo.getChassisHeight() != null && basVehicleInfo.getChassisHeight().compareTo(new BigDecimal(0)) >= 0)
                        && (basVehicleInfo.getLoadBearing() != null && basVehicleInfo.getLoadBearing() != 0)
                        && StringUtils.isNotEmpty(basVehicleInfo.getDriverLicense())
                        && StringUtils.isNotEmpty(basVehicleInfo.getManufacturer())
                        && StringUtils.isNotEmpty(basVehicleInfo.getIdCard())
                        && (basVehicleInfo.getCarLength() != null && basVehicleInfo.getCarLength().compareTo(new BigDecimal(0)) >= 0)
                        && (basVehicleInfo.getMaxNumber() != null && basVehicleInfo.getMaxNumber() != 0)
                        && (basVehicleInfo.getCarWidth() != null && basVehicleInfo.getCarWidth().compareTo(new BigDecimal(0)) >= 0)
                        && (basVehicleInfo.getMileage() != null && basVehicleInfo.getMileage() != 0)
                ) {
                    flag = true;
                }
                break;
            case "basMaterialBrand":
                BasMaterialBrand basMaterialBrand = (BasMaterialBrand) object;
                if (basMaterialBrand != null
                        && StringUtils.isNotEmpty(basMaterialBrand.getMaterialBrandName())) {
                    flag = true;
                }
                break;
            case "basProject":
                BasProject basProject = (BasProject) object;
                boolean flag1=true;
                int comparisonResult=-1;
                // 比较两个时间
                comparisonResult = basProject.getBeginDate().compareTo(basProject.getClosureDate());
                System.out.println(comparisonResult);
                if (comparisonResult >= 0){
                    flag1=false;
                }
                if (basProject != null
                        && StringUtils.isNotEmpty(basProject.getProjectName())
                        && basProject.getBuildUnitId() != null
                        && flag1) {
                    flag = true;
                }
                break;
        }
        return flag;
    }
}
